package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.Page;
import com.ruoyi.system.domain.vo.TSensitiveMessage;
import com.ruoyi.system.dto.SensitiveMessageDTO;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TSensitiveword;
import com.ruoyi.system.service.ITSensitivewordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 敏感词Controller
 * 
 * @author ruoyi
 * @date 2025-08-18
 */
@RestController
@RequestMapping("/system/sensitiveword")
@Api(tags = "敏感词Controller")
public class TSensitivewordController extends BaseController
{
    @Autowired
    private ITSensitivewordService tSensitivewordService;

    /**
     * 查询敏感词列表
     */
    @PreAuthorize("@ss.hasPermi('system:sensitiveword:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSensitiveword tSensitiveword)
    {
        startPage();
        List<TSensitiveword> list = tSensitivewordService.selectTSensitivewordList(tSensitiveword);
        return getDataTable(list);
    }

    /**
     * 查询命中敏感词列表
     */
    @PostMapping("/hit/list")
    public TableDataInfo page(@RequestBody SensitiveMessageDTO dto) {
        startPage();
        List<TSensitiveMessage> list = tSensitivewordService.hitListPage(dto);
        return getDataTable(list);
    }


    /**
     * 导出敏感词列表
     */
    @PreAuthorize("@ss.hasPermi('system:sensitiveword:export')")
    @Log(title = "敏感词", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSensitiveword tSensitiveword)
    {
        List<TSensitiveword> list = tSensitivewordService.selectTSensitivewordList(tSensitiveword);
        ExcelUtil<TSensitiveword> util = new ExcelUtil<TSensitiveword>(TSensitiveword.class);
        util.exportExcel(response, list, "敏感词数据");
    }

    /**
     * 获取敏感词详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sensitiveword:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tSensitivewordService.selectTSensitivewordById(id));
    }

    /**
     * 新增敏感词
     */
    @PreAuthorize("@ss.hasPermi('system:sensitiveword:add')")
    @Log(title = "敏感词", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSensitiveword tSensitiveword)
    {
        return toAjax(tSensitivewordService.insertTSensitiveword(tSensitiveword));
    }

    /**
     * 修改敏感词
     */
    @PreAuthorize("@ss.hasPermi('system:sensitiveword:edit')")
    @Log(title = "敏感词", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSensitiveword tSensitiveword)
    {
        return toAjax(tSensitivewordService.updateTSensitiveword(tSensitiveword));
    }

    /**
     * 删除敏感词
     */
    @PreAuthorize("@ss.hasPermi('system:sensitiveword:remove')")
    @Log(title = "敏感词", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSensitivewordService.deleteTSensitivewordByIds(ids));
    }
}
